<template>
  <div class="consulting">
    <el-main>
      <el-tabs v-model="activeIndex" @tab-click="handleClick">
        <ConsultingItem
          @chat="chat"
          @save="save"
          :activeIndex="activeIndex"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
          :list="list"
          :page="page"
        />

        <!-- <ConsultingItem
          @chat="chat"
          @save="save"
          :activeIndex="activeIndex"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
          :list="list"
          :page="page"
        />

        <ConsultingItem
          @chat="chat"
          @save="save"
          :activeIndex="activeIndex"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
          :list="list"
          :page="page"
        />

        <ConsultingItem
          @chat="chat"
          @save="save"
          :activeIndex="activeIndex"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
          :list="list"
          :page="page"
        />

        <ConsultingItem
          @chat="chat"
          @save="save"
          :activeIndex="activeIndex"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
          :list="list"
          :page="page"
        /> -->
      </el-tabs>
    </el-main>
    <ConsultingItem />
  </div>
</template>

<script>
import { content, userSave } from "@/api/admin";
import ConsultingItem from "@/components/ConsultingItem";
export default {
  components: {
    ConsultingItem,
  },
  data() {
    return {
      activeIndex: 0,
      list: [],
      textarea: "",
      textShow: true,
      page: [],
      size: null,
    };
  },

  mounted() {
    this.getdata();
  },
  methods: {
    handleClick(tab, event) {
      this.activeIndex = tab.index;
      this.getdata();
    },
    async getdata() {
      try {
        const res = await content({
          cid: this.activeIndex,
          size: this.size,
        });
        this.list = res.list;
        this.page = res.page;
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    async save(id, textarea) {
      try {
        await userSave({
          id: id,
          desc: textarea,
        });
        this.textShow = false;
        this.getdata();
        this.$message.success("保存成功");
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    chat(val) {
      if (val) {
        this.getdata();
      }
    },
    //每页下拉显示数据
    async handleSizeChange(size, index) {
      this.size = size;
      this.activeIndex = index;
      this.getdata();
      document.documentElement.scrollTop = 0;
    },
    //点击第几页
    async handleCurrentChange(currentPage, index) {
      this.size = currentPage;
      this.activeIndex = index;
      this.getdata();
      document.documentElement.scrollTop = 0;
    },
  },
};
</script>
